<?php
namespace Models;
/**
 * Description of Oddily
 *
 * @author buddha 
 */

class Oddily extends Base {

    /*public function getCleni($where)
    {
        return $this->db->query("
            SELECT *
            FROM pov_clenove cle
            WHERE $where
            ORDER BY fce DESC
                                ");

    }*/
    public function getCleni($where)
    {
        return $this->db->query("
            SELECT cle.id as id,
                   cle.nick as nick,
                   cle.foto as foto,
                   cle.fce as hodnost,
                   --cle.druzina as druzina_id,                   
                   --cle.oddil as oddil_id,
                   cle.jmeno as jmeno,
                   cle.prijmeni as prijmeni,
                   dru.druzina as druzina,
                   odd.oddil as oddil
            FROM pov_clenove cle
            LEFT JOIN pov_oddily odd ON(cle.oddil = odd.id)
            LEFT JOIN pov_druziny dru ON(cle.druzina = dru.id)
            WHERE $where
            ORDER BY cle.druzina ASC, cle.fce DESC
                                ");

    }
    /*public function getDruziny($where)
    {
        return $this->db->query("
            SELECT *
            FROM pov_druziny dru
            LEFT JOIN pov_clenove cle ON(clen.druzina = dru.id)
            WHERE $where
            ORDER BY fce DESC
                                ");

    }*/
    public function getOtazky($where)
    {
        return $this->db->query("
           SELECT   cle.id as id,
                    odp.odpoved as odpoved,
                    ota.otazka as otazka
            FROM pov_clenove_odpovedi odp
            INNER JOIN pov_clenove cle ON(odp.clen=cle.id)
            INNER JOIN pov_clenove_otazky ota ON(ota.id=odp.otazka)
            WHERE $where
            ORDER BY cle.id DESC");
    }
    public function getFrcky($where)
    {
        return $this->db->query("
           SELECT   cle.id as id,
                    frc.nazev as nazev,
                    frc.img as url
            FROM pov_fce fce
            INNER JOIN pov_clenove cle ON(fce.clen=cle.id)
            LEFT JOIN pov_fce_frcky frc ON(fce.frcka=frc.id)
            WHERE $where
            ORDER BY cle.id DESC");
    }
    public function getOddilpreloz($oddil)
    {
        return $this->db->query("
            SELECT oddil
            FROM pov_oddily
            WHERE id = '".$oddil."'
            ORDER BY id DESC
                                ");

    }
    public function getAktuality($oddil)
    {
        return $this->db->query("
            SELECT * 
            FROM pov_aktuality 
            WHERE oddil = '".$oddil."' 
            ORDER BY datum DESC 
            LIMIT 3
                                ");
    }
}